package com.richard.base.ui

import com.richard.base.ui.BaseActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

/***
 *  class MyActivity : AppCompatActivity(), CoroutineScope by MainScope() {
 *     override fun onDestroy() {
 *         cancel() // cancel is extension on CoroutineScope
 *     }
 *
 *     /*
 *      * Note how coroutine builders are scoped: if activity is destroyed or any of the launched coroutines
 *      * in this method throws an exception, then all nested coroutines are cancelled.
 *      */
 *     fun showSomeData() = launch { // <- extension on current activity, launched in the main thread
 *        // ... here we can use suspending functions or coroutine builders with other dispatchers
 *        draw(data) // draw in the main thread
 *     }
 * }
 *
 * 继承 这个类，可以方法中使用suspend
 * 与BaseVMActivity区别 如下：
 * Vm这个 是利用viewModelScope 来实现协程。而此类 是直接继承MainScope
 */
abstract class BaseActivityWithCoroutineScope : BaseActivity(), CoroutineScope by MainScope() {


    override fun setLayoutView() {
        setContentView(getLayoutResId())
    }

    abstract fun getLayoutResId(): Int

    override fun onDestroy() {
        super.onDestroy()
        cancel()
    }
}